## Process this file with autoconf to produce Makefile

@SET_MAKE@
CC        = @CC@
CPP       = @CPP@
CXX       = @CXX@
CFLAGS    = @CFLAGS@ @TICONV_CFLAGS@ @TICABLES_CFLAGS@ @TIFILES_CFLAGS@ @TICALCS_CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@ @GLADE_CFLAGS@ @SDL_CFLAGS@ @INCINTL@
LDFLAGS   = @LDFLAGS@ @TICONV_LIBS@ @TICABLES_LIBS@ @TIFILES_LIBS@ @TICALCS_LIBS@ @GLIB_LIBS@ @GTK_LIBS@ @GLADE_LIBS@ @LIBZ@ @SDL_LIBS@ $(extra_ldflags)
CXXFLAGS  = @CXXFLAGS@ @TICABLES_CFLAGS@ @TIFILES_CFLAGS@ @TICALCS_CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@ @GLADE_CFLAGS@
MOC       = @MOC@
DCOPIDL   = @DCOPIDL@
DCOPIDL2CPP = @DCOPIDL2CPP@
RC       ?= windres

kde       = @kde@
dbus      = @dbus@

#DESTDIR   =

ifneq (,$(findstring NO_GDB,$(CFLAGS)))
ifneq (,$(findstring __IPAQ__,$(CFLAGS)))
	LDFLAGS += @LIBINTL@
else
	LDFLAGS += @LTLIBINTL@
endif
endif

ifneq (,$(findstring __WIN32__,$(CFLAGS)))
	RESFILE = tiemu-rc.o
	LDFLAGS += -lcomdlg32 -lole32 -loleaut32 -luuid -lstdc++
	EXEEXT = .exe
	win32_OBJ = ipc/com/oleaut.o ipc/com/oleaut_i.o ipc/com/registry.o
else
	RESFILE =
	EXEEXT =
endif

INSTALL         = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA    = @INSTALL_DATA@
prefix          = @prefix@
exec_prefix     = @exec_prefix@
bindir          = @bindir@
libdir          = @libdir@
sysconfdir      = @sysconfdir@

.SUFFIXES: .o .c .cpp .h .m .i .S .rc .res
.NOTPARALLEL:

ifeq ($(kde), yes)
kdeincludes = @all_includes@
kdelibraries = @LIB_KDECORE@ @LIB_KDEUI@ @LIB_KIO@ @LIB_QT@ @KDE_LDFLAGS@ @QT_LDFLAGS@ @X_LDFLAGS@
kde_OBJ = kde/kde.o kde/kde-private.o   ipc/dcop/dcop.o ipc/dcop/dcop-private.o ipc/dcop/dcop_skel.o
kdeprivsources = kde/kde-private.cpp ipc/dcop/dcop-private.cpp ipc/dcop/dcop.kidl ipc/dcop/dcop_skel.cpp
kde/kde-private.cpp: kde/kde-private.h
	$(MOC) kde/kde-private.h -o kde/kde-private.cpp
ipc/dcop/dcop-private.cpp: ipc/dcop/dcop.h
	$(MOC) ipc/dcop/dcop.h -o ipc/dcop/dcop-private.cpp
ipc/dcop/dcop.kidl: ipc/dcop/dcop.h
	$(DCOPIDL) ipc/dcop/dcop.h > ipc/dcop/dcop.kidl
ipc/dcop/dcop_skel.cpp: ipc/dcop/dcop.kidl
	$(DCOPIDL2CPP) --no-stub ipc/dcop/dcop.kidl
FINALLINKCC = $(CXX)
else
FINALLINKCC = $(CC)
endif

DEFS=@DEFS@ \
	-DSHARE_DIR=\"${prefix}/share/tiemu\" \
	-DLOCALEDIR=\"${prefix}/share/locale\"
#	-DSHARE_DIR=\"$(pkgdatadir)\" \
#	-DLOCALEDIR=\"$(datadir)/locale\"

INCLUDES = \
	-I@top_srcdir@ -I$(includedir) \
	-DPREFIX=\"${prefix}\" -I. \
	-I./core -I./core/uae -I./core/ti_hw -I./core/ti_sw -I./core/dbg \
	-I./sound -I./gui -I./gui/calc -I./gui/debugger \
	-I./ipc/dcop -I./ipc/dbus -I./ipc/com \
	-I./kde \
	-I./misc

ifeq ($(dbus), yes)
LDFLAGS += @DBUS_GLIB_LIBS@
dbus_OBJ = ipc/dbus/dbus_ipc.o
ipc/dbus/dbus_glue.h: ipc/dbus/dbus_ipc.xml
	dbus-binding-tool --mode=glib-server --output=ipc/dbus/dbus_glue.h --prefix=tiemudbus ipc/dbus/dbus_ipc.xml
ipc/dbus/dbus_ipc.o: ipc/dbus/dbus_ipc.c ipc/dbus/dbus_ipc.h ipc/dbus/dbus_glue.h
	$(CC) $(INCLUDES) $(DEFS) -c $(CFLAGS) @DBUS_GLIB_CFLAGS@ ipc/dbus/dbus_ipc.c -o ipc/dbus/dbus_ipc.o
endif

# source files to build
core_uae_OBJ = \
	core/uae/cpuemu1.o core/uae/cpuemu2.o \
	core/uae/cpuemu3.o core/uae/cpuemu4.o \
	core/uae/cpuemu5.o core/uae/cpuemu6.o \
	core/uae/cpuemu7.o core/uae/cpuemu8.o \
	core/uae/cpudefs.o core/uae/cpustbl.o \
	core/uae/readcpu.o core/uae/fpp.o \
	core/uae/missing.o

ifneq (,$(findstring NO_GDB,$(CFLAGS)))
core_uae_xmalloc_OBJ = core/uae/xmalloc.o
else
core_uae_xmalloc_OBJ =
endif

core_tihw_OBJ = \
	core/ti_hw/dbus.o	\
	core/ti_hw/flash.o	\
	core/ti_hw/gscales.o	\
	core/ti_hw/hw.o 	\
	core/ti_hw/hwprot.o	\
	core/ti_hw/kbd.o 	\
	core/ti_hw/m68k.o	\
	core/ti_hw/mem.o 	\
	core/ti_hw/mem89.o	\
	core/ti_hw/mem89tm.o	\
	core/ti_hw/mem92.o	\
	core/ti_hw/mem92p.o	\
	core/ti_hw/memv2.o	\
	core/ti_hw/ports.o	\
	core/ti_hw/rtc_hw3.o	\
	core/ti_hw/tichars.o

core_tisw_OBJ = \
	core/ti_sw/er_codes.o \
	core/ti_sw/handles.o	\
	core/ti_sw/iodefs.o	\
	core/ti_sw/mem_map.o	\
	core/ti_sw/registers.o	\
	core/ti_sw/romcalls.o	\
	core/ti_sw/timem.o	\
	core/ti_sw/vat.o

core_OBJ = 			\
	core/error.o 		\
	core/engine.o		\
	core/images.o 		\
	core/interface.o	\
	core/state.o		\
	core/type2str.o		\
	core/hwpm.o

core_dbg_OBJ = \
	core/dbg/bkpts.o	\
	core/dbg/debug.o	\
	core/dbg/disasm.o	\
	core/dbg/fpudasm.o	\
	core/dbg/gdbcall.o

ifneq (,$(findstring NO_SOUND,$(CFLAGS)))
sound_OBJ =
else
sound_OBJ = \
	sound/audio.o \
	sound/stream.o
endif

misc_OBJ = \
	misc/cmdline.o 	\
	misc/files.o 	\
	misc/paths.o 	\
	misc/logging.o	\
	misc/rcfile.o 	\
	misc/screenshot.o \
	misc/tie_error.o 

gui_calc_OBJ = \
	gui/calc/calc.o		\
	gui/calc/dnd.o		\
	gui/calc/keymap.o	\
	gui/calc/keyboard.o	\
	gui/calc/keynames.o	\
	gui/calc/keypress.o	\
	gui/calc/popup.o	\
	gui/calc/screen.o	\
	gui/calc/skinkeys.o	\
	gui/calc/skinops.o

gui_debugger_OBJ = \
	gui/debugger/dbg_all.o		\
	gui/debugger/dbg_wnds.o		\
	gui/debugger/dbg_dock.o		\
	gui/debugger/dbg_bkpts.o	\
	gui/debugger/dbg_bits.o		\
	gui/debugger/dbg_cause.o	\
	gui/debugger/dbg_code.o		\
	gui/debugger/dbg_data.o		\
	gui/debugger/dbg_entry.o	\
	gui/debugger/dbg_heap.o		\
	gui/debugger/dbg_iop.o		\
	gui/debugger/dbg_mem.o		\
	gui/debugger/dbg_pclog.o	\
	gui/debugger/dbg_regs.o		\
	gui/debugger/dbg_romcall.o	\
	gui/debugger/dbg_stack.o	\
	gui/debugger/dbg_vectors.o

gui_logger_OBJ = \
	gui/logger/log_link.o

gui_OBJ = \
	gui/about.o							\
	gui/device.o							\
	gui/dboxes.o							\
	gui/filesel.o							\
	gui/fs_misc.o							\
	gui/infos.o							\
	gui/main.o							\
	gui/manpage.o							\
	gui/pbars.o							\
	gui/quicksend.o					\
	gui/refresh.o							\
	gui/release.o							\
	gui/romversion.o						\
	gui/scroptions.o						\
	gui/splash.o							\
	gui/support.o 							\
	gui/tsource.o 							\
	gui/wizard.o

core_gdb_DEP = \
	gdb/gdb/libgdb.ldflags \
	gdb/sim/m68k/libsim.a \
	gdb/bfd/libbfd.a \
	gdb/readline/libreadline.a \
	gdb/opcodes/libopcodes.a  \
	gdb/libiberty/libiberty.a

ifneq (,$(findstring NO_GDB,$(CFLAGS)))
libgdb_A =
else
libgdb_A = gdb/gdb/libgdb.a
endif

tiemu_OBJ = core/uae/newcpu.o \
	$(core_uae_OBJ) $(core_uae_xmalloc_OBJ) \
	$(core_OBJ) $(core_tihw_OBJ) $(core_tisw_OBJ) \
	$(core_dbg_OBJ) \
	$(sound_OBJ) \
	$(misc_OBJ) \
	$(gui_OBJ) $(gui_calc_OBJ) $(gui_debugger_OBJ) $(gui_logger_OBJ) \
	$(kde_OBJ) $(dbus_OBJ) $(win32_OBJ) \
	$(libgdb_A)

#rules:
all: uae gdbtk tiemu$(EXEEXT)

uae:
	cd core/uae && $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" gen
	cd core/uae && $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" all

gdbtk:
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	cd gdb && $(MAKE)
endif

ifneq (,$(findstring __WIN32__,$(CFLAGS)))
ifneq (,$(findstring NO_GDB,$(CFLAGS)))
tiemu.exe: $(tiemu_OBJ) $(RESFILE)
else
tiemu.exe: $(tiemu_OBJ) $(core_gdb_DEP) $(RESFILE)
endif
else
ifneq (,$(findstring NO_GDB,$(CFLAGS)))
tiemu: $(tiemu_OBJ)
else
tiemu: $(tiemu_OBJ) $(core_gdb_DEP)
endif
endif
ifneq (,$(findstring NO_GDB,$(CFLAGS)))
ifneq (,$(findstring __IPAQ__,$(CFLAGS)))
	$(FINALLINKCC) $(uae_OBJ) $(tiemu_OBJ) -o tiemu \
	$(LDFLAGS) $(CFLAGS) $(kdelibraries) \
	-Wl,--rpath,"$(prefix)/lib"
else
	../libtool --mode=link $(FINALLINKCC) $(uae_OBJ) $(tiemu_OBJ) $(RESFILE) \
	-o tiemu$(EXEEXT) $(LDFLAGS) $(CFLAGS) $(kdelibraries)
endif
else
# Force static linking for TCL-related stuff on OS X.
ifneq (,$(findstring __MACOSX__,$(CFLAGS)))
	sed <gdb/gdb/libgdb.ldflags >gdb/gdb/libgdb.ldflags.tmp -e 's,-L\([^ ]*\) -l\(tcl[0-9.]*\),\1/lib\2.a,g' -e 's,-L\([^ ]*\) -l\(tk[0-9.]*\),\1/lib\2.a,g' -e 's,-L\([^ ]*\) -l\(itcl[0-9.]*\),\1/lib\2.a,g' -e 's,-L\([^ ]*\) -l\(itk[0-9.]*\),\1/lib\2.a,g'
	mv -f gdb/gdb/libgdb.ldflags.tmp gdb/gdb/libgdb.ldflags
endif
ifneq (,$(findstring __IPAQ__,$(CFLAGS)))
	$(FINALLINKCC) $(uae_OBJ) $(tiemu_OBJ) -o tiemu \
    `sed <gdb/gdb/libgdb.ldflags 's,^\.\./,gdb/,;s, \.\./, gdb/,g;s, \./\.\./, gdb/,g'` \
	$(LDFLAGS) $(CFLAGS) $(kdelibraries) \
	-Wl,--rpath,"$(prefix)/lib"
else
	../libtool --mode=link $(FINALLINKCC) $(uae_OBJ) $(tiemu_OBJ) $(RESFILE) \
    `sed <gdb/gdb/libgdb.ldflags 's,^\.\./,gdb/,;s, \.\./, gdb/,g;s, \./\.\./, gdb/,g'` \
	-o tiemu$(EXEEXT) $(LDFLAGS) $(CFLAGS) $(kdelibraries)
endif
endif

.c.o:
	$(CC) $(INCLUDES) $(DEFS) -c $(CFLAGS) $< -o $@
	#../libtool --mode=compile $(CC) $(INCLUDES) $(DEFS) \
	#-c $(CFLAGS) $< -o $@

.cpp.o:
	$(CXX) $(INCLUDES) $(DEFS) -c $(CXXFLAGS) $(kdeincludes) $< -o $@
	#../libtool --mode=compile $(CC) $(INCLUDES) $(DEFS) \
	#-c $(CFLAGS) $< -o $@

tiemu-rc.o: ../build/mingw/tiemu.rc
	cd ../build/mingw && $(RC) tiemu.rc ../../src/tiemu-rc.o

clean:
	@cd core/uae && $(MAKE) clean
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	@cd gdb && $(MAKE) -k clean || :
endif
	@rm -f $(tiemu_OBJ) tiemu tiemu.exe tiemu-rc.o $(kdeprivsources)

distclean: clean
	@cd core/uae && $(MAKE) distclean
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	@cd gdb && $(MAKE) -k distclean || :
endif
	@rm -Rf .libs

distdir: clean
ifneq (,$(findstring NO_GDB,$(CFLAGS)))
	cp -rl core kde ipc gui misc sound ../@PACKAGE@-@VERSION@/src
else
	cp -rl core kde ipc gui misc sound \
	gdb cleangdbsources.sh	../tiemu-@VERSION@/src
endif
	find ../tiemu-@VERSION@/src -name .svn -exec rm -rf "{}" \\; 2>/dev/null

dos2unix:
	dos2unix
	lowercase
	uppercase

install: tiemu$(EXEEXT)
	@$(INSTALL) -d $(DESTDIR)${prefix}/bin
	$(INSTALL) -m755 tiemu$(EXEEXT) $(DESTDIR)${prefix}/bin/
ifneq (,$(findstring __WIN32__,$(CFLAGS)))
	$(INSTALL) -m755 ipc/com/tiemups.dll $(DESTDIR)${prefix}/bin/
	$(INSTALL) -m755 ipc/com/oleaut.tlb $(DESTDIR)${prefix}/bin/tiemu.tlb
endif
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	cd gdb/tcl && $(MAKE) install INSTALL_ROOT="$(DESTDIR)"
	cd gdb/tk && $(MAKE) install INSTALL_ROOT="$(DESTDIR)"
	cd gdb/itcl && $(MAKE) install DESTDIR="$(DESTDIR)"
	cd gdb/libgui && $(MAKE) install DESTDIR="$(DESTDIR)"
	cd gdb/gdb && $(MAKE) install-gdbtk DESTDIR="$(DESTDIR)"
endif

install-without-tcl-tk: tiemu$(EXEEXT)
	@$(INSTALL) -d $(DESTDIR)$(prefix)/bin
	$(INSTALL) -m755 tiemu$(EXEEXT) $(DESTDIR)${prefix}/bin/
ifneq (,$(findstring __WIN32__,$(CFLAGS)))
	$(INSTALL) -m755 ipc/com/tiemups.dll $(DESTDIR)${prefix}/bin/
	$(INSTALL) -m755 ipc/com/oleaut.tlb $(DESTDIR)${prefix}/bin/tiemu.tlb
endif
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	cd gdb/itcl && $(MAKE) install DESTDIR="$(DESTDIR)"
	cd gdb/libgui && $(MAKE) install DESTDIR="$(DESTDIR)"
	cd gdb/gdb && $(MAKE) install-gdbtk DESTDIR="$(DESTDIR)"
endif

install-without-tcl-tk-itcl: tiemu$(EXEEXT)
	@$(INSTALL) -d $(DESTDIR)$(prefix)/bin
	$(INSTALL) -m755 tiemu$(EXEEXT) $(DESTDIR)${prefix}/bin/
ifneq (,$(findstring __WIN32__,$(CFLAGS)))
	$(INSTALL) -m755 ipc/com/tiemups.dll $(DESTDIR)${prefix}/bin/
	$(INSTALL) -m755 ipc/com/oleaut.tlb $(DESTDIR)${prefix}/bin/tiemu.tlb
endif
ifeq (,$(findstring NO_GDB,$(CFLAGS)))
	cd gdb/libgui && $(MAKE) install DESTDIR="$(DESTDIR)"
	cd gdb/gdb && $(MAKE) install-gdbtk DESTDIR="$(DESTDIR)"
endif

regsvr:
ifeq ($(OSTYPE),msys)
	$(DESTDIR)${prefix}/bin/tiemu -RegServer
	regsvr32 //s $(DESTDIR)${prefix}/bin/tiemups.dll
else
	echo "Error: This target is for native MSYS compilations only!"
	exit 1
endif

uninstall:
	rm -f ${prefix}/bin/tiemu$(EXEEXT)
